import React, { Component, createContext } from "react";

const { Provider, Consumer } = createContext();

function ComB() {
  return (
    <Consumer>
        {(val) => {
            return <div>ComB --- {val   }</div>;
        }}
    </Consumer>
  );
}

function ComA() {
  return (
    <div>
      ComA
      <ComB />
    </div>
  );
}

export default class App extends Component {
  constructor() {
    super();
    this.state = { age: 20 };
  }
  
  render() {
    return (
      <Provider value={this.state.age}>
        <div>
          App3
          <ComA />
        </div>
      </Provider>
    );
  }

  componentDidMount() {
    
  }
}
